﻿using eDataBoard.basePage;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web;

namespace eDataBoard.basePage.log
{
    static class Log
    {
        public static void LogWrite(string str, string logname)
        {       //项目根目录 HttpContext.Current.Server.MapPath("~")
            // Directory.CreateDirectory
            string dir = Environment.CurrentDirectory + "\\Log\\";
            string path = dir + logname + DateTime.Now.ToString("yyyyMMdd") + ".txt";
            if (!Directory.Exists(dir))
            {
                Directory.CreateDirectory(dir);
            }

            if (!File.Exists(path))
            {
                FileStream fs = new FileStream(path, FileMode.Create, FileAccess.ReadWrite);

                StreamWriter sw = new StreamWriter(fs);
                sw.Write(str+"\r\n");
                sw.Flush();
                sw.Close();
            }
            else
            {
                FileStream fs = new FileStream(path, FileMode.Append);
                //文本写入
                StreamWriter sw = new StreamWriter(fs);
                sw.Write(str + "\r\n");
                sw.Flush();
                sw.Close();
            }
        }
    }
}
